package com.nikitova.craps3d.view {
	import com.carlcalderon.arthropod.Debug;
	import com.nikitova.craps3d.constants.statemachine.StateTransitions;
	import com.nikitova.craps3d.view.components.GameDataPreloader;

	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	import org.puremvc.as3.multicore.utilities.startupmanager.StartupManager;

	/**
	 * ...
	 * @author schranz
	 */
	public class GameDataPreloaderMediator extends Mediator
	{
		static public const NAME : String = "GameDataPreloaderMediator";

		public function GameDataPreloaderMediator(gameDataPreloader : GameDataPreloader, mediatorName : String = NAME) 
		{
			super(mediatorName, gameDataPreloader);
		}

		override public function onRegister() : void
		{
			showView(false);
		}

		private function showView(value : Boolean) : void
		{
			component.visible = value;
		}

		override public function listNotificationInterests() : Array
		{		
			return [	
						StateTransitions.SHOW_PRELOADER,
						StateTransitions.HIDE_PRELOADER,
						StartupManager.LOADING_PROGRESS,
					];
		}

		override public function handleNotification( note : INotification ) : void
		{
			switch (note.getName())
			{
				case StateTransitions.SHOW_PRELOADER:
					showView(true);
					break;
				case StateTransitions.HIDE_PRELOADER:
					showView(false);
				break;
				case StartupManager.LOADING_PROGRESS:
					var percents:Number = note.getBody() as Number;
					Debug.log("Percents: "+percents, Debug.GREEN);
					component.updatePercents(percents);
				break;
			}
		}

		public function get component() : GameDataPreloader
		{
			return viewComponent as GameDataPreloader;
		}
	}
}